package com.qf.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @Description: 公用常量
 * @Data: 2022/9/13 16:02
 * @Pacakge: com.qf.config
 * @ClassName: MyIntercept
 * @Author: fan
 * 配置拦截器
 */
public class MyIntercept implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //1>获取Session域对象
        HttpSession session = request.getSession();
        //2>获取session的存储对象
        Object user = session.getAttribute("user");
        //3>判断
        if (user != null){
            return true;
        }
        //重定向至登录页面
        response.sendRedirect("/user/login");
        return false;
    }

}
